﻿/***************************************************************************
//* Foxit Software Inc.
//* Copyright(C) 2005-2012, all rights reserved.
//*
//* The following code is copyrighted and contains proprietary information
//* and trade secrets of Foxit Software Inc.                                                      *
***************************************************************************/

/**
* 平台环境以及浏览器信息
*/

define(function (require, exports, module) {
    var FXREADER = require('./FXReader.js');
   
    var envWrapper = (function () {
        var agent = navigator.userAgent.toLowerCase();
        var opera = window.opera;
        var env =
		{
		    /**
		    IE 
		    */
		    ie: /msie/.test(agent) && !/opera/.test(agent)&& document.all,
		    /**
		     * IE11 at least.
		    */
		    ieAtLeast11: !/msie/.test(agent) && /trident/.test(agent) && !/opera/.test(agent),
		    /**
		    Opera
		    */
		    opera: (!!opera && opera.version),

		    /**
		    *   WebKit based browser, such as Safari.
		    */
		    webkit: (agent.indexOf(' applewebkit/') > -1),
		    chrome: agent.indexOf('chrome') > -1,
		    /**
		    * Macintosh.
		    */
		    mac: (agent.indexOf('macintosh') > -1),

		    /**
		    *  quirks mode 
		    */
		    quirks: (document.compatMode == 'BackCompat'),

		    /**
		    *  mobile like
		    */
		    mobile: (jQuery.browser.mobile === true),

		    /**
		    *  iPhone/iPad/iPod 
		    */
		    iOS: /(ipad|iphone|ipod)/.test(agent),


		    /**
		    https
		    */
		    secure: location.protocol == 'https:'
		};

        /**
        * Gecko based browser, such as Firefox.
        */
        env.gecko = (navigator.product == 'Gecko' && !env.webkit && !env.opera);

        var version = 0;

        // Internet Explorer 6.0+
        if (env.ie) {
            version = parseFloat(agent.match(/msie (\d+)/)[1]);

            /**
            ie8
            */
            env.ie8 = !!document.documentMode && document.documentMode < 8;

            /**
            ie8 standard mode.
            */
            env.ie8Compat = document.documentMode == 8;

            /**
             ie9 standard mode.
            */
            env.ie9Compat = document.documentMode == 9;

            /**
             ie7 standard mode.
            */
            env.ie7Compat = ((version == 7 && !document.documentMode)
					|| document.documentMode == 7);

            /**
            ie6 standard mode.
            */
            env.ie6Compat = (version < 7 || env.quirks);
        }

        // Gecko.
        if (env.gecko) {
            var geckoRelease = agent.match(/rv:([\d\.]+)/);
            if (geckoRelease) {
                geckoRelease = geckoRelease[1].split('.');
                version = geckoRelease[0] * 10000 + (geckoRelease[1] || 0) * 100 + (geckoRelease[2] || 0) * 1;
            }
        }

        // Opera 9.50+
        if (env.opera)
            version = parseFloat(opera.version());

        // WebKit 522+ (Safari 3+)
        if (env.webkit)
            version = parseFloat(agent.match(/ applewebkit\/(\d+)/)[1]);

        env.version = version;

        /**
		check whether current browser is compatible.
         */
        env.IsCompatible =
			env.iOS && version >= 534 ||

			!env.mobile && (

			(env.ie && version >= 6) ||
			(env.gecko && version >= 10801) ||
			(env.opera && version >= 9.5) ||
			(env.webkit && version >= 522) ||
			false);

        return env;
    })();

    /**
     * @name FXREADER.Environment
     * @namespace 
     * @description environment of the browser.
     */
    FXREADER.Environment = 
    {
    		/**
		    IE 
		    */
		    ie: envWrapper.ie,
		    chrome: envWrapper.chrome,
		    /**
		     * IE11 at least.
		    */
		    ieAtLeast11: envWrapper.ieAtLeast11,
		    /**
		    Opera
		    */
		    opera: envWrapper.opera,

		    /**
		    *   WebKit based browser, such as Safari.
		    */
		    webkit: envWrapper.webkit,
		   
		    /**
		    * Macintosh.
		    */
		    mac: envWrapper.mac,

		    /**
		    *  quirks mode 
		    */
		    quirks: envWrapper.quirks,

		    /**
		    *  mobile like
		    */
		    mobile: envWrapper.mobile,

		    /**
		    *  iPhone/iPad/iPod 
		    */
		    iOS: envWrapper.iOS,


		    /**
		    https
		    */
		    secure: envWrapper.secure,
		    version: envWrapper.version,
		    /**
            ie8
            */
            ie8 : envWrapper.ie8,
            
            /**
            ie8 standard mode.
            */
            ie8Compat : envWrapper.ie8Compat,

            /**
             ie9 standard mode.
            */
            ie9Compat : envWrapper.ie9Compat,

            /**
             ie7 standard mode.
            */
            ie7Compat : envWrapper.ie7Compat,

            /**
            ie6 standard mode.
            */
            ie6Compat : envWrapper.ie6Compat,
            IsCompatible : envWrapper.IsCompatible
    };
    
    return FXREADER.Environment;
});